#!/bin/bash
set -u 

export DATA_CENTERS="DUMMY"
export FS_LOG_PATH=$(pwd)/tmp
export EXP='r1234'
export STATION='ts'

# PLOG="./plog -t"
PLOG="./plog"

mkdir -p $FS_LOG_PATH

log=$FS_LOG_PATH/$EXP$STATION.log
logs=$(echo $FS_LOG_PATH/$EXP${STATION}{,_full}.log{,.gz})
rm $FS_LOG_PATH/*

echo test > $log


echo 
echo
echo plain log
echo ============

echo $PLOG $EXP
$PLOG $EXP
echo $PLOG -l
$PLOG -l
echo $PLOG -z $EXP
$PLOG -z $EXP
echo $PLOG -l -z
$PLOG -l -z

echo 
echo
echo compressed file
echo ===============
echo

gzip $log
echo $PLOG $EXP
$PLOG $EXP
echo $PLOG -l
$PLOG -l
echo $PLOG -z $EXP
$PLOG -z $EXP
echo $PLOG -l -z
$PLOG -l -z


rm $log.gz

echo 
echo
echo multicast
echo =========

echo "2016.243.18:00:00.08#rdtca#" >> $log
echo $PLOG $EXP
$PLOG $EXP
rm $FS_LOG_PATH/*
echo "2016.243.18:00:00.08#rdtca#" >> $log
echo $PLOG -l
$PLOG -l
rm $FS_LOG_PATH/*
echo "2016.243.18:00:00.08#rdtca#" >> $log
echo $PLOG -z $EXP
$PLOG -z $EXP
rm $FS_LOG_PATH/*
echo "2016.243.18:00:00.08#rdtca#" >> $log
echo $PLOG -l -z
$PLOG -l -z
rm $FS_LOG_PATH/*


echo 
echo
echo different files
echo ==============

echo plain
echo -----

for l in $logs; do
    if [[ $l =~ gz$ ]]; then
        echo "OK" | gzip > $l
    else
        echo "OK" > $l
    fi
    echo $l:
    $PLOG $EXP
    rm $l
done

echo mcast
echo -----

for l in $logs; do
    if [[ $l =~ gz$ ]]; then
        echo -e "OK\n2016.243.18:00:00.08#rdtca#" | gzip > $l
    else
        echo -e "OK\n2016.243.18:00:00.08#rdtca#" > $l
    fi
    echo $l:
    $PLOG $EXP
    rm $l
done

echo 
echo
echo conflicts
echo =========

echo "" > $log
for l in $logs; do
    echo "" > $l
    $PLOG $EXP
done
rm $FS_LOG_PATH/*



echo 
echo
echo Open file
echo =========

echo "2016.243.18:00:00.08#rdtca#" >> $log
tail -f $log >/dev/null & 
echo $PLOG $EXP
$PLOG $EXP
rm $FS_LOG_PATH/*


echo 
echo
echo Quiet mode
echo ===========
echo "2016.243.18:00:00.08#rdtca#" >> $log
echo $PLOG -q $EXP
$PLOG -q $EXP
rm $FS_LOG_PATH/*

echo
echo
echo Direct File mode
echo ===============
echo test > $log
$PLOG $log
